<?php
class IndexBuilder extends Builder {
	private $mainDir;
	private $inputFile = 'html/index.tpl';
	private $outputFile = 'index.html';
	private $scriptDirs = ['js/', 'js/Api/'];
	public function __construct () {
		$this->mainDir = __DIR__.'/../';
		$this->inputFile = $this->mainDir.$this->inputFile;
		$this->outputFile = $this->mainDir.$this->outputFile;
		parent::__construct($this->inputFile);
		$this->getScripts();
	}
	private function getScripts () {
		$scripts = array('angular/angular.js', 'angular/angular-resource.js');
		array_map(function ($dir) use (&$scripts) {
			$files = scandir($this->mainDir.$dir);
			array_map(function ($item) use (&$scripts, $dir) {
				if(is_file($this->mainDir.$dir.$item)) {
					$scripts[] = $dir.$item;
				}
			}, $files);
		}, $this->scriptDirs);
		$this->setItem('scripts', $scripts);
	}
	public function fetch () {
		file_put_contents($this->outputFile, parent::fetch());
	}
}
?>